﻿Ext.BLANK_IMAGE_URL = "/script/ext/resources/images/s.gif";
Ext.onReady(function () {
    var modelid = jQuery.query.get("modelid");

    var form = new Ext.form.FormPanel({
        region: 'center',
        title: "采购申请",
        margins: "5",
        layout: 'form',
        frame: true,
        labelAlign: "right",
        labelWidth: 80,
        buttonAlign: "center",
        items: [{ //行1
            layout: 'column', //定义为列模式
            items: [{
                layout: 'form',
                items: [{
                    xtype: 'textfield',
                    name: "PurchaseTitle",
                    fieldLabel: "采购标题",
                    blankText: '采购标题不能为空',
                    allowBlank: false
                }]
            }, {
                layout: 'form',
                items: [{
                    xtype: 'textfield',
                    name: "PurchaseName",
                    fieldLabel: "采购物品名称",
                    blankText: '姓名不能为空',
                    allowBlank: false
                }]
            }]
        },
        new Ext.form.HtmlEditor({
            fieldLabel: '清单', //标签名称 
            anchor: '100%',
            name: "PurchaseContent"
        })],
        buttons: [
                {
                    text: "申请采购",
                    handler: function () {
                        if (form.form.isValid()) {
                            alert(0);
                            var params = {
                                PurchaseTitle: form.getForm().findField("PurchaseTitle").getValue(),
                                PurchaseName: form.getForm().findField("PurchaseName").getValue(),
                                PurchaseContent: form.getForm().findField("PurchaseContent").getValue(),
                                PurchaseState: 0
                            };
                            Ext.Ajax.request({
                                url: "server/Purchase/PurchaseApply.aspx?modelid=" + modelid,
                                params: params,
                                success: function (response) {
                                    var json = Ext.util.JSON.decode(response.responseText);
                                    if (json.success) {
                                        Ext.Msg.alert("申请成功", json.msg, function () {
                                            groupStore.load({ params: { start: 0, limit: pageSize} });
                                        });
                                        form.getForm().reset();
                                    } else {
                                        Ext.Msg.alert("错误", json.msg);
                                    }
                                },
                                failure: function (response) { Ext.Msg.alert("请求失败", response.responseText); }
                            });
                        }
                    }
                }, {
                    text: "重置", handler: function () { form.getForm().reset(); }
                }]
    });

    /*创建页面布局*/
    var viewport = new Ext.Viewport({
        layout: 'border',
        items: [form]
    }); /*布局加载*/viewport.doLayout();

    /*延时加载*/
    setTimeout(function () { Ext.get('loading').remove(); Ext.get('loading-mask').fadeOut({ remove: true }); }, 400);

    grid.on('rowdblclick', function (g, index, e) {
        var r = g.getSelectionModel().getSelected();
        Ext.get('parent_id').dom.value = r.get("ContactsTypeID");
    });

});